import type { LocalVersionItem } from "@/modules/dev-env/common/types.ts";
import path from "@/framework/util/path.ts";

export interface GenMongodbConfigOptions {
  /**
   * 数据目录
   */
  dbPath?: string;
}

/**
 * 生成mongodb默认配置
 * @param version 版本信息
 * @param opts 配置项
 */
export function getMongodbDefaultConfig(version: LocalVersionItem, opts?: GenMongodbConfigOptions) {
  const dataPath = opts?.dbPath ?? path.join(version.installPath, "data");

  return `# docs: https://www.mongodb.com/zh-cn/docs/manual/reference/configuration-options/

storage:
  dbPath: ${path.join(dataPath, "db")}

systemLog:
   destination: file
   path: ${path.join(dataPath, "mongod.log")}
   logAppend: true

net:
   bindIp: 0.0.0.0
   port: 27017

setParameter:
   enableLocalhostAuthBypass: false
`;
}
